package com.yanqu.road.server.cmd.activity.hongxian;

import com.yanqu.road.entity.activity.hongxian.HongXianUserData;
import com.yanqu.road.entity.activity.hongxian.config.HongXiuConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HongXianActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.hongxian.HongXianActivityModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.hongxian.HongXianActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_HONG_XIAN_SAVE_CLIENT, desc = "保存客户端动画")
public class HongXianClientAnimSaveCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        HongXiuConfig config = HongXianActivityMgr.getConfig();
        // 没有活动
        if (!ActivityMgr.activityInTimeAndShowTime(HongXianActivityMgr.getActivityInfo()) || config == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        HongXianActivityProto.HongXianClientAnimSaveReqMsg reqMsg = HongXianActivityProto.HongXianClientAnimSaveReqMsg.parseFrom(packet.getBytes());

        if(reqMsg.getClient().length() > 30){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        HongXianUserData userData = player.getModule(HongXianActivityModule.class).getUserData();
        if(userData != null){
            userData.setClientAnim(reqMsg.getClient());
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        player.sendPacket(Protocol.U_HONG_XIAN_SAVE_CLIENT, HongXianActivityProto.HongXianClientAnimSaveRespMsg.newBuilder().setRet(ret));
    }
}
